package com.example.exam3;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        String str1 = "BBC ABCDAB ABCDABCDABDE";
        String str2 = "ABCDABD";
        System.out.println(Arrays.toString(kmpMap("AAA")));
    }

    public static int[] kmpMap(String string) {
        int[] next = new int[string.length()];
        next[0] = 0;
        for (int i = 1, j = 0; i < string.length(); i++) {
            if (string.charAt(i) == string.charAt(j)) {
                j++;
            }
            next[i] = j;
        }
        return next;
    }
}
